package com.kangkang.leetcode10;

public class Test8 {
    public static void main(String[] args) {
        int[] a = {7, 1, 5, 3, 6, 4};
        System.out.println(Solution8.maxProfit(a));
    }
}
class Solution8 {
    public static int maxProfit(int[] prices) {

        int maxValue = 0;
        for (int i = 0; i < prices.length; i++) {
            if(i != prices.length -1 && prices[i]<prices[i+1]){
                maxValue-=prices[i];
            }
            if(i != 0 && prices[i]>prices[i-1]){
                maxValue+=prices[i];
            }
        }
        return maxValue;
    }
}